<template>
    <div class="mainDiv">
        <div class="rowHead">
            <el-button type="success" icon="plus" @click="add" v-qx="permission.add" v-show="noadd">新增等级</el-button>
        </div>
        <el-table :data="list" :stripe="true" height="100%">
            <el-table-column prop="gradeid" label="权限等级"></el-table-column>
            <el-table-column prop="remarks" label="等级说明" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="edittime" label="最后修改时间">
                <template scope="scope">
                    {{scope.row.edittime|dateTime}}
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template scope="scope">
                    <el-button-group>
                        <el-tooltip content="编辑权限" placement="left" :open-delay="800" v-qx="permission.edit">
                            <el-button type="warning" icon="el-icon-edit" size="mini" @click="edit(scope.row)"></el-button>
                        </el-tooltip>
                        <el-tooltip content="设置权限" placement="top" :open-delay="800" v-qx="permission.sets">
                            <el-button type="primary" icon="el-icon-h-set2" size="mini" @click="setgrade(scope.row.id)"></el-button>
                        </el-tooltip>
                        <el-tooltip content="删除当前等级" placement="top" :open-delay="800" v-qx="permission.del">
                            <el-button type="danger" icon="el-icon-h-del" size="mini" @click="deleteGrade(scope.row.id)"></el-button>
                        </el-tooltip>
                    </el-button-group>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import C from '#/src/common/common.js'

export default {
    name: 'permissionLevel',
    data() {
        return {
            list: [],
            permission: {
                add: 'orgrade_add',
                edit: 'orgrade_edit',
                sets: 'orgrade_set',
                del: 'orgrade_del',
            },
            noadd: true
        }
    },
    methods: {
        setgrade: async function(id) {
            let data = await C.openBrowserWindow('/editGrade', { id: id }, {
                transparent: true,
                frame: false,
                width: 1200,
                height: 760,
                useSpa: true,
                spaModel: 'organization'
            })
            if (data) {
                C.success(data.data.info)
            }
        },
        add: async function() {
            let data = await C.openBrowserWindow('/addotherPermission', {}, {
                transparent: true,
                frame: false,
                width: 400,
                height: 280,
                useSpa: true,
                spaModel: 'organization'
            })
            if (data) {
                C.success(data.data)
                this.getList()
            }
        },
        edit: async function(row) {
            let data = await C.openBrowserWindow('/addotherPermission', { row: row }, {
                transparent: true,
                frame: false,
                width: 400,
                height: 280,
                useSpa: true,
                spaModel: 'organization'
            })
            if (data) {
                C.success(data.data)
                this.getList()
            }
        },
        deleteGrade: function(id) {
            C.confirm('确定删除自定义权限？', async() => {
                let data = await C.ajax('/organization/rule/deleteothergrade', { id: id }, 'post')
                if (data) {
                    C.success(data.data)
                    this.getList()
                }
            })
        },
        getList: async function() {
            let data = await C.ajax('/organization/rule/getgradeallot', { type: this.$route.params.type })
            if (data) {
                this.list = data
                if (data.length > 10) {
                    this.noadd = false
                } else {
                    this.noadd = true
                }
            }
        }
    },
    mounted: function() {
        this.getList()
    }
}
</script>